import 'package:flutter/material.dart';
import 'package:flutter_mode/other/bloc_demo.dart';
import 'package:flutter_mode/other/inherited_demo.dart';
import 'package:flutter_mode/other/redux_demo.dart';
import 'package:flutter_mode/other/rx_demo.dart';
import 'package:flutter_mode/other/scoped_mode_demo.dart';
import 'package:flutter_mode/utils.dart';
import 'package:flutter_mode/zyj/ui/webview.dart';

import 'provider_demo.dart';

class DataSharePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    final appInherited = AppInheritedWidget.of(context);
    final appDataManager = appInherited.appDataManager;
    var user = appDataManager.user;

    var items = {
      'Inherited Widgets${user == null ? '' : '(${user.name})'}': () async =>
          pushMaterial(context, InheritedDemoPage()),
      'Scoped model': () => pushMaterial(context, ScopedModeDemoPage()),
      'Redux': () => pushMaterial(context, ReduxDemo()),
      'provider': () => pushMaterial(context, ProviderDemo()),
      'BLoC 结合StreamBuilder使用': () => pushMaterial(context, BLoCDemo()),
      'RxDart 测试': () => pushMaterial(context, RxDartDemo()),
      'doc：https://www.jianshu.com/u/f0cd06a06592': () => pushMaterial(
          context,
          WebViewPage(
            title: 'doc',
            url: 'https://www.jianshu.com/u/f0cd06a06592',
          )),
    };

    return Scaffold(
      appBar: AppBar(
        title: Text('数据缓存和数据共享'),
      ),
      body: ListView.separated(
        itemBuilder: (context, position) {
          var item = items.entries.elementAt(position);
          return ListTile(
            title: Text(item.key),
            onTap: item.value,
          );
        },
        itemCount: items.length,
        separatorBuilder: (context, position) => Divider(
              height: 1,
            ),
      ),
    );
  }
}
